const download = require('download-git-repo')
const ora = require('ora')
const chalk = require('chalk')

const downloadFn = (url, project) => {
    console.log('----------')
    console.log(url)
    console.log(project)
    const spinner = ora().start()
    spinner.text = '模板下载中......'
    // 注意： github、gitlab 等之外的都需要加direct：
    download(url, project, {clone: true} ,(err) => {
        if(!err) {
            spinner.succeed(chalk.blue.bold('下载成功'))
            console.log( chalk.blue.bold('Done!!! you can run: '))
            console.log('cd ' + project)
            console.log('npm install ' )
            console.log('npm run dev')
        }else{
            spinner.fail(`下载失败，失败原因：${chalk.red(err)}`)
        }
    })
}

module.exports = downloadFn